package thread.synchronize;

/**
 * Created by jianweilin on 16/9/29.
 */
public class SynchronizedTest {
    private Integer count = 0;

    public synchronized void inc(){
        for(int i=0;i<10;i++) {
            count++;
            System.out.println("name = " + Thread.currentThread().getName() + " count = " + count);
        }
    }


    public static void main(String[] args) {
        SynchronizedTest test = new SynchronizedTest();
       Thread t1 =  new Thread(() -> {
           test.inc();
       },"t1");

        Thread t2 =  new Thread(() -> {
            test.inc();
        },"t2");

        t1.start();
        t2.start();

    }
}
